/**
 * This file is part of Wasagent.
 *
 * Wasagent is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Wasagent is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Wasagent. If not, see <http://www.gnu.org/licenses/>.
 * 
 * ServerNameTest.java : Gets from the SOAP connection the name of the
 *                       server that is tested.
 *
 *
 */

package net.wait4it.wasagent.tests;

import javax.management.ObjectName;

import net.wait4it.wasagent.jmx.JmxService;

import com.ibm.websphere.management.AdminClient;

/**
 * @author Yann Lambret
 *
 */
public class ServerNameTest {

	private static final String query = "WebSphere:*,type=Server";

	public String run(AdminClient client, ObjectName perfMbean) {
		String serverName;

		try {
			ObjectName mbean = JmxService.getMbean(client, query);
			serverName = client.getAttribute(mbean, "name").toString();
		} catch (Exception e) {
			System.out.println("ServerNameTest.java: " + e.toString());
			return null;
		}

		return serverName;
	}

}
